package com.dz51.core.basedao.base;

import org.hibernate.Session;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Collection;

/**
 * @Title: IAbstractBaseDao.java
 * @Package com.dz51.core.basedao
 * @Description: <p>基础抽象dao层接口
 * <p>------------- 提供Hibernate Session获取、JDBC Connection ----------
 * <p>------------- 基础实体save, delte, find, update  ----------
 * @author Zhaoqt  
 * @date 2014-5-4 上午2:36:10
 * @version V1.0
 */
public abstract interface IAbstractBaseDao<E> {

	/**
	 * @Title: getHibernateSession
	 * @Description: <p>获取session 
	 * 				 <p>{@link org.springframework.orm.hibernate3.HibernateTemplate#getSession()}}
	 * @param 
	 * @throws Exception    
	 * @return Session
	 */
	public abstract Session getHibernateSession() throws Exception;
	
	/**
	 * @Title: getJDBCConnection
	 * @Description: <p>获取 JDBCConnection
	 * 				 <p>{@link org.springframework.jdbc.datasource.DataSourceUtils#getConnection(javax.sql.DataSource)}
	 * @param 
	 * @throws Exception    
	 * @return Connection
	 */
	public abstract Connection getJDBCConnection() throws Exception;
	
	/**
	 * @Title: releaseJDBCConnection
	 * @Description: 关闭jdbc connection
	 * @param  resultSet
	 * @param  statement
	 * @param  connection
	 * @throws Exception    
	 * @return void
	 */
	public abstract void releaseJDBCConnection(
			ResultSet resultSet, Statement statement, Connection connection)
			    throws Exception;
	
	/**
	 * @Title: addEntity
	 * @Description: 实体储存 
	 * @param entity
	 * @throws Exception    
	 * @return void
	 */
	public abstract void addEntity(E entity) throws Exception; 
	
	/**
	 * @Title: batchAddEntities
	 * @Description: 实体批量储存
	 * @param collection
	 * @throws Exception    
	 * @return void
	 */
	public abstract void batchAddEntities(Collection<E> collection) throws Exception;
	
	/**
	 * @Title: updateEntityByPK
	 * @Description: 主键更新实体 该方法不支持动态更新慎用
	 * @param entity
	 * @throws Exception    
	 * @return void
	 */
	public abstract void updateEntityByPK(E entity) throws Exception;
	
	/**
	 * @Title: deleteEntityByPK
	 * @Description: 主键删除实体 
	 * @param entity
	 * @throws Exception    
	 * @return void
	 */
	public abstract void deleteEntityByPK(E entity) throws Exception;
	
	/**
	 * @Title: batchDeleteEntities
	 * @Description: 实体批量删除 
	 * @param collection
	 * @throws Exception    
	 * @return void
	 */
	public abstract void batchDeleteEntities(Collection<E> collection) throws Exception;
	
	/**
	 * @Title: loadEntity
	 * @Description:  session.load(..)
	 * @param className
	 * @param id
	 * @throws Exception    
	 * @return E
	 */
	public abstract E loadEntity(Class<E> className, Serializable id) throws Exception;
	
	/**
	 * @Title: getEntity
	 * @Description: session.get(..) 
	 * @param className
	 * @param id
	 * @throws Exception    
	 * @return E
	 */
	public abstract E getEntity(Class<E> className, Serializable id) throws Exception;

	/**
	 * 声明实体
	 * super.setEntityClass(Entity.class);
	 * @Title: setEc
	 * @param className
	 * @throws Exception
	 */
	public abstract void setEC(Class<E> className) throws Exception;
}
